﻿using Demo.Models;
using Microsoft.AspNetCore.Mvc;
using QuickDotNetCore.Attributrs;
using QuickDotNetCore.DAO.Banner;
using QuickDotNetCore.Templates;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Demo.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [ApiGroupSort(0)]
    public class BannerController: ControllerBase
    {
        private IBannerDAO bannerDAO;
        public BannerController(IBannerDAO bannerDAO) {
            this.bannerDAO = bannerDAO;
        }

        [HttpGet("getBanner")]
        public BaseResponse<List<BannerDO>> GetAllBanner() {
            return BaseResponse<List<BannerDO>>.Success(bannerDAO.All());
        }

        [HttpPost("addOrUpdate")]
        public BaseResponse<string> AddOrUpdate(BannerDO banner,int rtid)
        {
            bannerDAO.AddOrUpdate(banner, (d => d.tid == rtid));
            return BaseResponse<string>.Success("ODK");
        }
    }
}
